package com.jingdianjichi.subject.domain.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 线程池的管理/分配等
 * @return:
 * @Author:  sky
 * @date:  2024/11/21 21:05
 */
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "labelThreadPool")
    public ThreadPoolExecutor getLabelThreadPool(){
        // 不用默认的Executors.defaultThreadFactory()
        // 用自己定制的线程工厂
        return new ThreadPoolExecutor(20,100,5,
                TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
                new CustomNameThreadFactory("Label"),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }


}
